package com.water.wfo.user.ability.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.water.wfo.sys.pojo.entity.SyslogEntity;
import com.water.wfo.sys.pojo.request.DataDictionaryRequest;
import com.water.wfo.sys.pojo.response.ParameterResponse;
import com.water.wfo.user.ability.SyslogAbility;
import com.water.wfo.user.mapper.SyslogMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * <p>
 * 系统日志表 服务实现类
 * </p>
 *
 * @author water&7
 * @since 2024-07-24
 */
@Slf4j
@Component
public class SyslogAbilityImpl implements SyslogAbility {

    @Autowired
    private SyslogMapper syslogMapper;
    @Override
    public int insert(SyslogEntity entity) {
        return syslogMapper.insert(entity);
    }

    @Override
    public ParameterResponse querySyslogEntityBy(DataDictionaryRequest entity) {
        List<SyslogEntity> syslogEntities = null;
        try {
            PageHelper.startPage(entity.getPageNum(),entity.getPageSize());
            syslogEntities = syslogMapper.querySyslogEntityBy(entity);
        } catch (Exception e) {
            log.error(e.getMessage());
        } finally {
            PageHelper.clearPage();
        }
        //得到分页的结果对象
        PageInfo<SyslogEntity> personPageInfo = new PageInfo<>(syslogEntities);
        //得到分页中条目对象
        List<SyslogEntity> pageList = personPageInfo.getList();
        ParameterResponse response = new ParameterResponse();
        response.setResult(pageList);
        response.setTotal(personPageInfo.getTotal());
        return response;
    }

    @Override
    public int deleteBatchByIds(List<Long> list) {
        return syslogMapper.deleteBatchByIds(list);
    }
}
